package com.gexin.model.product;

import com.gexin.model.product.base.BaseProductTagRel;
import com.jfinal.plugin.activerecord.Db;

import java.util.List;

/**
 * 业务名称: t_product_tag_rel(标签关联表)
 */
@SuppressWarnings("serial")
public class ProductTagRel extends BaseProductTagRel<ProductTagRel> {
	public static final ProductTagRel dao = new ProductTagRel();

	/**
	 * 删除删除专题的商品关联信息
	 * @param tag_id
	 */
	public void delTagRelsByTagProductId(Integer tag_id, Integer product_id) {
		Db.update("delete from t_product_tag_rel where tag_id = ? and product_id = ?", tag_id, product_id);
	}

	/**
	 * 根据专题id删除关联信息
	 * @param tag_id
	 */
	public void delTagRelsByTagId(Integer tag_id) {
		Db.update("delete from t_product_tag_rel where tag_id = ?", tag_id);
	}


	/**
	 * fang 2016-06-20 根据产品 product_id 找到 对应的 tag
	 *
	 */
	public List<ProductTagRel> getTagRelsByProductId(String product_id) {
		String sql = "select * from t_product_tag_rel where product_id=?";
		return dao.find(sql, product_id);
	}

	/**
	 * fang 2016-06-21 根据product_id 删除所以的dao
	 *
	 */
	public void deleteByProductId(int product_id) {
		String sql = " delete from t_product_tag_rel where product_id=?";
		Db.update(sql, product_id);
	}

}
